<?php
//主机
define("HOST","localhost");  
//用户名
define("USER","root");  
//密码
define("PASS","root");
// 连接mysql
$link = new mysqli(HOST,USER,PASS);
//开启session机制
session_start();
//获取用户名
$username = $_POST['username'];
//获取密码
$password = $_POST['password'];
if(isset($_SESSION['username'])){
     
}else{
  echo "<script>alert('非法操作！！！请先登录');location.href='login.html';</script>";
}
// 编码设置
$link->query("set names 'utf8'");
//创建数据库
$sql1 = "CREATE DATABASE test";
if ($link->query($sql1) === TRUE) {
    echo "首次访问，创建数据库test成功!!!";
} else {
     
}

        //选择数据库test
		mysqli_select_db($link,"test");
		//创建会员members表
	    $sql1 = "CREATE TABLE members (
		id int(10) unsigned NOT NULL auto_increment,
		name varchar(10) NOT NULL,
		gender varchar(3) NOT NULL,
		age int(10) NOT NULL,
		phone varchar(20) NOT NULL,
		address varchar(20) NOT NULL,
		membernum varchar(20) NOT NULL,
		birth date NOT NULL,
		introduction text NOT NULL,
		PRIMARY KEY  (id)
	  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=46 ";
    if ($link->query($sql1) === TRUE) {
        echo "首次访问创建members表成功！！！请刷新";
	} 
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>会员信息管理系统</title>
	<link rel="stylesheet" type="text/css" href="css/index.css"/>
<style type="text/css">

</style>
</head>
<body>
	<div class="wrapper">
		<h1>会员信息管理系统</h1>
		<div class="add">
			<a href="add.html">添加会员信息</a>
			<a href="chaxun.html">查询会员信息</a>
			<a href="php/loginout.php?action=logout">退出</a>
		</div>
		<table width="100%" border="1" class ="gridtable">
			<tr>
				<th>ID</th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>电话</th>
				<th>住址</th>
				<th>会员码</th>
				<th>出生日期</th>
				<th>会员简介</th>
				<th>操作</th>
			</tr>
			<?php
				// 从test中查询到members数据表，返回数据库结果集,并按照id降序排列  
				$sql = 'select * from members order by id asc';
				// $sql = "select * from members where age='30' or name='小王1'";
				// 结果集
				$result = $link->query($sql);
				// 解析结果集,$row为新闻所有数据，$newsNum为新闻数目
				$newsNum=mysqli_num_rows($result); 
				//循环输出表中的内容 
				for($i=0; $i<$newsNum; $i++){
					$row = mysqli_fetch_assoc($result);
					echo "<tr>";
					echo "<td>{$row['id']}</td>";
					echo "<td>{$row['name']}</td>";
					echo "<td>{$row['gender']}</td>";
					echo "<td>{$row['age']}</td>";
					echo "<td>{$row['phone']}</td>";
					echo "<td>{$row['address']}</td>";
					echo "<td>{$row['membernum']}</td>";
					echo "<td>{$row['birth']}</td>";
					echo "<td>{$row['introduction']}</td>";
					echo "<td>
							<a href='javascript:del({$row['id']})'><div class='div_d'>删除</div></a>
							<a href='php/edit.php?id={$row['id']}'><div class='div_u'>修改</div></a>
						  </td>";
					echo "</tr>";
				}
				// 释放结果集
				mysqli_free_result($result);
				mysqli_close($link);
			?>
		</table>
	</div>
	<script type="text/javascript">
		function del (id) {
			if (confirm("确定删除这条新闻吗？")){
				window.location = "php/action-del.php?id="+id;
			}
		}
	</script>
</body>
</html>
